# -*- coding: utf-8 -*-
"""
 @Time    : 2021/1/26 下午4:03
 @Author  : tgy
 
"""


def test01():
    ...
    ls = [1, 2, 3, 4]
    # for l in reversed(ls):
    #     print(l)

    for i,val in enumerate(ls,2):
        print(i,val,sep=':')


class Person:
    __slots__ = ['names']

    def __init__(self):
        self.names = []

    def add_name(self, name):
        self.names.append(name)

    # 倒序列遍历
    def __reversed__(self):
        ...
        for i in range(len(self.names) - 1,-1,-1):
            ...
            yield self.names[i]

    # 正序遍历
    def __iter__(self):
        for i in range(len(self.names)):
            yield self.names[i]

if __name__ == '__main__':
    ...
    test01()
    person = Person()
    person.add_name('zhangsan')
    person.add_name('tony')
    person.add_name('lisi')

    for name in reversed(person):
        print(name)

    for name in person:
        print(name)